#ifndef _DSWCONSOLE_GPRS_MSGSESSION_H
#define _DSWCONSOLE_GPRS_MSGSESSION_H
#include "libdswservercenter/dswserversession.h"
#include "dswconsole_gprs_session_base.h"

#define MSG_SOCKET_INDEX 4

class CDswconsole_gprs_msgsession : public CDswconsole_gprs_session_base
{
public:
	CDswconsole_gprs_msgsession(LPST_ENV_T pEnv, EN_MISSION_TYPE nType, CB_ON_MISSION_NOTIFY pFunc, void* pParent, struct bufferevent *pBev);
	virtual ~CDswconsole_gprs_msgsession();
public:
	virtual void ProcessData(char* pData, int nLen);

	static bool cbDealRegisterToP2PServer(void* pMsgReq,const char* pMsgResp, void* pCaller){return ((CDswconsole_gprs_msgsession*)pCaller)->DealRegisterToP2PServer(pMsgReq, pMsgResp);};
	bool DealRegisterToP2PServer(void * pMsgReq, const char* pMsgResp);
	static bool cbDealHeartResp(void* pMsgReq,const char* pMsgResp, void* pCaller){return ((CDswconsole_gprs_msgsession*)pCaller)->DealHeartResp(pMsgReq, pMsgResp);};
	bool DealHeartResp(void * pMsgReq, const char* pMsgResp);
	static bool cbDealSetParamReq(void* pMsgReq,const char* pMsgResp, void* pCaller){return ((CDswconsole_gprs_msgsession*)pCaller)->DealSetParamReq(pMsgReq, pMsgResp);};
	bool DealSetParamReq(void * pMsgReq, const char* pMsgResp);
	static bool cbDealGetParamReq(void* pMsgReq,const char* pMsgResp, void* pCaller){return ((CDswconsole_gprs_msgsession*)pCaller)->DealGetParamReq(pMsgReq, pMsgResp);};
	bool DealGetParamReq(void * pMsgReq, const char* pMsgResp);
private:
	static void cbOnHeartBeetReq(int fd, short events, void* ctx){((CDswconsole_gprs_msgsession*)ctx)->OnHeartBeetReq(fd, events);};
	void OnHeartBeetReq(int fd, short events);
private:
	void SendMsg(char * pMsg);
	void MakeP2PXmlHead(CMarkup* pxml, char* pMsgType);
	void MakeRespXML(const char* pMsgType, CMarkup & xml, int nerrcode);
	int MakePayloadLength(char* pData, int nLen){return ((pData[2] << 8 | pData[1]) + 1);};
	void PorcessMsg(char* pMsg, int nLen);
	void CheckPUCID(CMarkup* pXml);
	void SetPoliceParam(void* pMsg);
	void SetSystemParam(void* pMsg);
	void SetAlarmParam(void* pMsg);
	void GetAlarmParam(CMarkup& xml);
private:
	EN_MISSION_TYPE m_nMissionType;
	CB_ON_MISSION_NOTIFY m_pNotifyFunc;
	void* m_pParent;

	int m_nWantSize;
	char *m_pBuffer, *m_pRecvPos;

	char m_sPucID[128], m_sWanIp[64];
	timer_param_t m_nTask_HeartBeet;
};

#endif

